﻿@using TestConsole

@if (Controls != null)
{
    @foreach (var ctl in Controls)
    {
        if (ctl is InputInfo input)
        {
            if (input.GType == GType.none)
            {
                <Card>
                    <CardHeader>
                        <Tag Color="Color.Primary">Input:@input.InputType</Tag>
                        <BootstrapInput DisplayText="标题" TValue="string" @bind-Value="input.Label"></BootstrapInput>
                    </CardHeader>
                    <CardBody>
                        <p class="card-text">Id:@input.Id</p>
                        <p class="card-text">Name:@input.Name</p>
                        <p class="card-text">Class:@input.Class</p>
                        <p class="card-text">InputType:@input.InputType</p>
                    </CardBody>
                </Card>
            }
            else
            {
                <Card>
                    <CardHeader>
                        <Tag Color="Color.Active">Group</Tag>
                        <BootstrapInput DisplayText="组标题" TValue="string" @bind-Value="input.Label"></BootstrapInput>
                    </CardHeader>
                    <CardBody>
                        @foreach (InputInfo childInput in input.Children)
                        {
                            <Card>
                                <CardHeader>
                                    <Tag Color="Color.Primary">Input:@childInput.InputType</Tag>
                                    <BootstrapInput DisplayText="标题" TValue="string" @bind-Value="childInput.Label"></BootstrapInput>
                                </CardHeader>
                                <CardBody>
                                    <p class="card-text">Id:@childInput.Id</p>
                                    <p class="card-text">Name:@childInput.Name</p>
                                    <p class="card-text">Class:@childInput.Class</p>
                                    <p class="card-text">InputType:@childInput.InputType</p>
                                </CardBody>
                            </Card>
                        }
                    </CardBody>
                </Card>
            }

        }
        else if (ctl is TextareaInfo area)
        {
            <Card>
                <CardHeader>
                    <Tag Color="Color.Primary">Textarea</Tag>
                    <BootstrapInput TValue="string" DisplayText="标题" @bind-Value="area.Label"></BootstrapInput>
                </CardHeader>
                <CardBody>
                    <p class="card-text">Id:@area.Id</p>
                    <p class="card-text">Name:@area.Name</p>
                    <p class="card-text">Class:@area.Class</p>
                </CardBody>
            </Card>
        }
        else if (ctl is SelectInfo select)
        {
            <Card>
                <CardHeader>
                    <Tag Color="Color.Primary">Select</Tag>
                    <BootstrapInput TValue="string" DisplayText="标题" @bind-Value="select.Label"></BootstrapInput>
                </CardHeader>
                <CardBody>
                    <p class="card-text">Id:@select.Id</p>
                    <p class="card-text">Name:@select.Name</p>
                    <p class="card-text">Class:@select.Class</p>
                </CardBody>
                <CardFooter>
                    <p>可选值范围:</p>
                    @foreach (var item in select.Options)
                    {
                        <p>
                            Value:
                            <span>@item.Value</span>
                            Text:
                            <BootstrapInput TValue="string" @bind-Value="item.Text"></BootstrapInput>
                        </p>
                    }
                </CardFooter>
            </Card>
        }
        else
        {
            throw new Exception($"{ctl.GetType().Name}目前代码不支持");
        }
    }
}
